package com.tmpt.controller.action;


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tmpt.controller.taglib.UrlAuthUtils;
import com.tmpt.dto.*;
import com.tmpt.freemarker.exec.FreemarkerGen;
import com.tmpt.service.IMenuService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.googlecode.genericdao.search.Search;
import com.opensymphony.xwork2.ActionSupport;
import com.tmpt.utils.report.ExcelUtils;
import com.tmpt.service.IQuartzService;
import com.tmpt.service.ISecurityV2Service;
import com.tmpt.service.ITemplateService;
import com.tmpt.utils.DateTool;
import com.tmpt.utils.JsonMap;
import com.tmpt.utils.JsonPaginationUtils;
import com.tmpt.utils.WebUtils;

@Controller
@Scope("prototype")
public class TemplateAction extends ActionSupport{
	private Logger log = Logger.getLogger(this.getClass());
	
	private int page;
	private int rows;
	private String recordDateStart;
	private String recordDateEnd;
	private String sortColumn;
	private String sortOrder;
	private String menu2Id;

	private long a1TemplateTableId;
	private String tableName;
	private String tableNameShow;
	private String primaryKey;
	
	private String columnName;
	private String columnShowName;
	private String columnNameSql;
	private String columnNameSqlSum;
	private int needSum;
	private int isFrozenColumn;
	private int sort;
	private int isHidden;
	
	private long a1TemplateConditionId;
	private int isMultiQuery;
	
	private String itemName;
	private String url;
	
	private String keyName;
	private String valueName;

	private String menu1Id;
	private String optionId;
	
	//添加编辑数据时，做定向
	private String keyRandom;
	//上个页面通过右击列表 传过来的 id和row; ps:右击模板x列，看模板列列表，自动加载列数，要传模板id找表名
	private String _id;
	private String _keyRandom;
	//template 生成 menu 时，指定页面类型
	private String pageType;
	private String menu2Name;
	
	private String result;	
	private List<Map<String,Object>> jsonArrayResult = new ArrayList<Map<String,Object>>();
	A1OperationlogDto oprDtoBack = new A1OperationlogDto(WebUtils.getRequest(), A1OperationlogDto.UserTypeBack);
	
	@Resource ITemplateService templateService;
	@Resource ISecurityV2Service securityV2Service;
	@Resource IQuartzService quartzService;
	@Resource IMenuService menuService;
	

    /**
	 * 分页查询列表
	 * @return
	 */
	public String queryListBySearch(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			HttpServletRequest request = WebUtils.getRequest();
			HttpSession session = request.getSession();
			String keyRandom = request.getParameter("_keyRandom");
			session.setAttribute("_keyRandom", keyRandom);
			String requireUrl = request.getRequestURI().toString();
			String queryString = request.getQueryString();
			//  /zpmng//admin123/template/templateAjax_queryListBySearch.action
			String contextPath = request.getContextPath();

			Map<String,String[]> paramMap1 = new HashMap<String, String[]>();
			paramMap1.putAll(request.getParameterMap());
			paramMap1.put("page",new String[]{String.valueOf(page-1)});
			//map to jsonstring
			String paramJson = JsonMap.map2Json(paramMap1);

			//Others parameters
			String userId = WebUtils.getUserId();
			Map<String,Object> paramMap = new HashMap<String, Object>();
			paramMap.put("userId", userId);
			paramMap.put("menu2Id",menu2Id);
			paramMap.put("contextPath",contextPath);
			paramMap.put("requireUrl",requireUrl);
			paramMap.put("queryString",queryString);

			Result resultObj =  templateService.paginationBySearch(paramJson,paramMap);
			if(!resultObj.isSuccess()){
				this.result = "error:"+resultObj.getContent();
				JsonPaginationUtils.responseWriter(response, this.result);
				return "jsonResult";
			}
			Map<String,Object> resultMap = resultObj.getResultMap();
			
			List<Map<String,Object>> list = (List<Map<String,Object>>)resultMap.get("rows");
			int total = 0;
			if(resultMap.get("total") != null){
				total = Integer.parseInt(resultMap.get("total").toString());
			}
			
			//查询历史记录时，这个值没有返回
			//报表导出sql和查询参数存入session供导出时使用 by xiaohui
			String reportSqlString = "";
			if(resultMap.get("reportString")!=null){
				reportSqlString = resultMap.get("reportString").toString();
				session.setAttribute(keyRandom+"_reportSqlString", reportSqlString);
				session.setAttribute(keyRandom+"_reportParam",resultMap.get("reportParam"));
			}

			JSONArray jsonArrayRows = JSONArray.fromObject(list);
			JSONArray jsonArrayFooter = null;
			if(resultMap.get("footer")!=null){
				jsonArrayFooter = JSONArray.fromObject(resultMap.get("footer"));
			}
			
	        JSONObject json = new JSONObject();
	        json.put("total", total);
	        json.put("rows", jsonArrayRows);
	        json.put("reportSqlString",reportSqlString);
	        if(jsonArrayFooter!=null){
	        	json.put("footer", jsonArrayFooter);
	        }

			this.result = json.toString();
			JsonPaginationUtils.responseWriter(response, this.result);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "jsonResult";
	}
	

	/**
	 * 日志报表下载
	 * @return
	 * @throws IOException 
	 */
	public String downloadReport() throws IOException{
		HttpSession session = WebUtils.getRequest().getSession();
		HttpServletResponse response = WebUtils.getResponse();
		HttpServletRequest request = WebUtils.getRequest();
		try {
			/*String _keyRandom = (String)session.getAttribute("_keyRandom");
			if(_keyRandom==null || _keyRandom.equals("")){
				this.result = "请先查询，后下载";
				JsonPaginationUtils.responseWriter(response, this.result);
				return null;
			}

			String reportSqlString = (String)session.getAttribute("reportSqlString");
			if(reportSqlString==null || reportSqlString.equals("")){
				this.result = "请先查询，后下载";
				JsonPaginationUtils.responseWriter(response, this.result);
				return null;
			}*/

			String _keyRandom = request.getParameter("_keyRandom");
			String reportSqlString = (String)session.getAttribute(_keyRandom+"_reportSqlString");
			List<Object> paramList = (List<Object>)session.getAttribute(_keyRandom+"_reportParam");
			A1TemplateTableDto templateTable = templateService.getTemplateTable(_keyRandom);
			//List<Map<String,Object>> columnList = templateService.getColumnList(_keyRandom);
			List<Map<String,Object>> reportList = templateService.queryReportBySearch(templateTable, reportSqlString,paramList);
			ExcelUtils.downloadReport4Template(reportList, templateTable, response);
		} catch (Exception e) {
			e.printStackTrace();
			this.result = "系统出错";
			JsonPaginationUtils.responseWriter(response, this.result);
			return null;
		}
		
		return null;
	}
	
	
	
	public String tableListBySearch(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			Search search = new Search();
			search.setPage(page-1);
			search.setMaxResults(rows);
			
			if("desc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, true);
			}else if("asc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, false);
			}else{
				search.addSort("id", false);
			}

			search.addFilterGreaterOrEqual("createDate", DateTool.string2Date(recordDateStart, "yyyy-MM-dd"));
			search.addFilterLessOrEqual("createDate", DateTool.string2DateEnd(recordDateEnd, "yyyy-MM-dd"));

			if(JsonPaginationUtils.checkDateResponseWriter(recordDateStart, recordDateEnd, response)){
				return "jsonResult";
			}
			
			PaginationDto<A1TemplateTableDto> pagination = templateService.paginationA1TemplateTableListBySearch(search);

			this.result = JsonPaginationUtils.paginationToJson(pagination);
			JsonPaginationUtils.responseWriter(response, this.result);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "jsonResult";
	}
	
	public String addA1TemplateTable(){
		Result result = new Result();
		try {
			A1TemplateTableDto dto = new A1TemplateTableDto();
			dto.setKeyRandom(DateTool.getCurrentDateStr1("yyyyMMddHHmmssSSS"));
			//dto.setSql("");
			dto.setTableName(tableName);
			dto.setTableNameShow(tableNameShow);
			dto.setPrimaryKey(primaryKey);
			result = templateService.addA1TemplateTable(dto);
			JSONObject jo = JSONObject.fromObject(result.getResultMap());
	    	this.result = jo.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "操作失败："+e.getLocalizedMessage();
			result.fault("系统出错:"+e.getLocalizedMessage());
    		this.result = JSONObject.fromObject(result.getResultMap()).toString();
		}
		return "jsonResult";
	}
	

	public String tableColumnListBySearch(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			Search search = new Search();
			search.setPage(page - 1);
			search.setMaxResults(rows);
			
			if("desc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, true);
			}else if("asc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, false);
			}else{
				search.addSort("id", false);
			}

			search.addFilterEqual("a1TemplateTable.id", a1TemplateTableId);
			search.addFilterGreaterOrEqual("createDate", DateTool.string2Date(recordDateStart, "yyyy-MM-dd"));
			search.addFilterLessOrEqual("createDate", DateTool.string2DateEnd(recordDateEnd, "yyyy-MM-dd"));

			if(JsonPaginationUtils.checkDateResponseWriter(recordDateStart, recordDateEnd, response)){
				return "jsonResult";
			}
			
			PaginationDto<A1TemplateColumnDto> pagination = templateService.paginationA1TemplateColumnListBySearch(search);

			this.result = JsonPaginationUtils.paginationToJson(pagination);
			JsonPaginationUtils.responseWriter(response, this.result);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "jsonResult";
	}

	public String addA1TemplateColume(){
		Result result = new Result();
		try {
			A1TemplateColumnDto dto = new A1TemplateColumnDto();
			dto.setColumnName(columnName);
			dto.setColumnShowName(columnShowName);
			dto.setColumnNameSql(columnNameSql);
			dto.setColumnNameSqlSum(columnNameSqlSum);
			dto.setIsFrozenColumn(isFrozenColumn);
			dto.setNeedSum(needSum);
			dto.setSort(sort);
			dto.setIsHidden(isHidden);
			
			result = templateService.addA1TemplateColumn2Table(dto, a1TemplateTableId);
			JSONObject jo = JSONObject.fromObject(result.getResultMap());
	    	this.result = jo.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "操作失败："+e.getLocalizedMessage();
			result.fault("系统出错:"+e.getLocalizedMessage());
    		this.result = JSONObject.fromObject(result.getResultMap()).toString();
		}
		return "jsonResult";
	}

	public String addA1TemplateCondition(){
		Result result = new Result();
		try {
			A1TemplateConditionDto dto = new A1TemplateConditionDto();
			dto.setColumnName(columnName);
			dto.setColumnShowName(columnShowName);
			dto.setIsMultiQuery(isMultiQuery);
			
			result = templateService.addA1TemplateCondition2Table(dto, a1TemplateTableId);
			JSONObject jo = JSONObject.fromObject(result.getResultMap());
	    	this.result = jo.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "操作失败："+e.getLocalizedMessage();
			result.fault("系统出错:"+e.getLocalizedMessage());
    		this.result = JSONObject.fromObject(result.getResultMap()).toString();
		}
		return "jsonResult";
	}
	
	public String addA1TemplateRightMenu(){
		Result result = new Result();
		try {
			A1TemplateRightMenuDto dto = new A1TemplateRightMenuDto();
			dto.setItemName(itemName);
			dto.setUrl(url);
			
			result = templateService.addA1TemplateRightMenu2Table(dto, a1TemplateTableId);
			JSONObject jo = JSONObject.fromObject(result.getResultMap());
	    	this.result = jo.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "操作失败："+e.getLocalizedMessage();
			result.fault("系统出错:"+e.getLocalizedMessage());
    		this.result = JSONObject.fromObject(result.getResultMap()).toString();
		}
		return "jsonResult";
	}

	public String addA1TemplateConditionMuiltiQuery(){
		Result result = new Result();
		try {
			A1TemplateConditionMultiQueryDto dto = new A1TemplateConditionMultiQueryDto();
			dto.setKeyName(keyName);
			dto.setValueName(valueName);
			
			result = templateService.addA1TemplateMultiQuery2Condition(dto, a1TemplateConditionId);
			
			JSONObject jo = JSONObject.fromObject(result.getResultMap());
	    	this.result = jo.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "操作失败："+e.getLocalizedMessage();
			result.fault("系统出错:"+e.getLocalizedMessage());
    		this.result = JSONObject.fromObject(result.getResultMap()).toString();
		}
		return "jsonResult";
	}
	

	public String tableConditionListBySearch(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			Search search = new Search();
			search.setPage(page - 1);
			search.setMaxResults(rows);
			
			if("desc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, true);
			}else if("asc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, false);
			}else{
				search.addSort("id", false);
			}

			search.addFilterEqual("a1TemplateTable.id", a1TemplateTableId);
			search.addFilterGreaterOrEqual("createDate", DateTool.string2Date(recordDateStart, "yyyy-MM-dd"));
			search.addFilterLessOrEqual("createDate", DateTool.string2DateEnd(recordDateEnd, "yyyy-MM-dd"));

			if(JsonPaginationUtils.checkDateResponseWriter(recordDateStart, recordDateEnd, response)){
				return "jsonResult";
			}

			PaginationDto<A1TemplateConditionDto> pagination = templateService.paginationA1TemplateConditionListBySearch(search);

			this.result = JsonPaginationUtils.paginationToJson(pagination);
			JsonPaginationUtils.responseWriter(response, this.result);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "jsonResult";
	}

	public String tableConditionMultiQueryListBySearch(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			Search search = new Search();
			search.setPage(page-1);
			search.setMaxResults(rows);
			
			if("desc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, true);
			}else if("asc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, false);
			}else{
				search.addSort("id", false);
			}

			search.addFilterEqual("a1TemplateCondition.id", a1TemplateConditionId);
			search.addFilterGreaterOrEqual("createDate", DateTool.string2Date(recordDateStart, "yyyy-MM-dd"));
			search.addFilterLessOrEqual("createDate", DateTool.string2DateEnd(recordDateEnd, "yyyy-MM-dd"));

			if(JsonPaginationUtils.checkDateResponseWriter(recordDateStart, recordDateEnd, response)){
				return "jsonResult";
			}
			
			PaginationDto<A1TemplateConditionMultiQueryDto> pagination = templateService.paginationA1TemplateConditionMultiQueryListBySearch(search);

			this.result = JsonPaginationUtils.paginationToJson(pagination);
			JsonPaginationUtils.responseWriter(response, this.result);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "jsonResult";
	}
	

	public String tableRightMenuListBySearch(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			Search search = new Search();
			search.setPage(page-1);
			search.setMaxResults(rows);
			
			if("desc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, true);
			}else if("asc".equals(sortOrder) && sortColumn!=null){
				search.addSort(sortColumn, false);
			}else{
				search.addSort("id", false);
			}

			search.addFilterEqual("a1TemplateTable.id", a1TemplateTableId);
			search.addFilterGreaterOrEqual("createDate", DateTool.string2Date(recordDateStart, "yyyy-MM-dd"));
			search.addFilterLessOrEqual("createDate", DateTool.string2DateEnd(recordDateEnd, "yyyy-MM-dd"));

			if(JsonPaginationUtils.checkDateResponseWriter(recordDateStart, recordDateEnd, response)){
				return "jsonResult";
			}
			
			PaginationDto<A1TemplateRightMenuDto> pagination = templateService.paginationA1TemplateRightMenuListBySearch(search);

			this.result = JsonPaginationUtils.paginationToJson(pagination);
			JsonPaginationUtils.responseWriter(response, this.result);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "jsonResult";
	}

	

	/**
	 * 通过模板插入记录
	 * @return
	 */
	public String addeditData(){
		Result result = new Result();
		try {
			HttpServletRequest request = WebUtils.getRequest();
			Map<String,String[]> paramMap = request.getParameterMap();
			//map to jsonstring
			String paramJson = JsonMap.map2Json(paramMap);
			String _keyRandom = request.getParameter("_keyRandom");
			//加入管理员
			String createMan = WebUtils.getUsername();
			org.json.JSONObject jo1 = new org.json.JSONObject(paramJson);
			jo1.put("createMan", new String[]{createMan});
			paramJson = jo1.toString();
			
			String id = paramMap.get("id")[0];
			if(id!=null && !id.equals("")){
				//修改操作
				result = templateService.editData(_keyRandom, id, paramJson);
			}else{
				//添加操作
				result = templateService.addData(_keyRandom, paramJson);
			}
			
			this.jsonArrayResult.add(result.getResultMap());
			
		}catch (Exception e) {
			e.printStackTrace();
			result.fault("error:系统出错:"+e.getLocalizedMessage());
			this.jsonArrayResult.add(result.getResultMap());
		}
		return "jsonArray";
	}


	/**
	 * 伪删除
	 * @return
	 */
	public String removeData(){
		Result resultObj = new Result();
		try {
			HttpServletRequest request = WebUtils.getRequest();
			//加入管理员
			String createMan = WebUtils.getUsername();

			resultObj = templateService.removeData(_keyRandom, _id, createMan);

			this.jsonArrayResult.add(resultObj.getResultMap());

		}catch (Exception e) {
			e.printStackTrace();
			resultObj.fault("error:系统出错:"+e.getLocalizedMessage());
			this.jsonArrayResult.add(resultObj.getResultMap());
		}
		return "jsonArray";
	}


	/**
	 * 自动给模板表列，加载列数据，方便配置
	 * @return
	 */
	public String loadColumn(){
		Result resultObj = new Result();
		try {
			templateService.loadColumn(_id);
			//String json = this.jsonArrayResult.toString();
			JSONObject json = new JSONObject();
			json.put("msg", "ssssssssss");
			
	    	this.result = json.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
	}

	/**
	 * 查询一级菜单：模板生成二级菜单中要查询一级菜单上交
	 * @return
	 */
	public String queryMenu1List(){
		try {
			Result<A2Menu1Dto> resultObj = securityV2Service.queryMenu1List();
			List<A2Menu1Dto> menu1DtoList = resultObj.getResultList();

			//list to jsonarray
			this.jsonArrayResult = new ArrayList<Map<String,Object>>();
			for(A2Menu1Dto menu1Dto:menu1DtoList){
				Map<String,Object> jo = new HashMap<String, Object>();
				jo.put("id", menu1Dto.getId());
				jo.put("text", menu1Dto.getText());
				this.jsonArrayResult.add(jo);
			}
			
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonArray";
	}

	/**
	 * 模板生成二级菜单
	 * @return
	 */
	public String template2menu(){
		HttpServletResponse response = ServletActionContext.getResponse();
		long userId = Long.parseLong(WebUtils.getUserId());
		try {
			Map<String,Object> mapParam = new HashMap<String, Object>();
			mapParam.put("_templateTableId",Long.parseLong(_id));
			mapParam.put("menuIdParent",Long.parseLong(menu1Id));
			mapParam.put("menuName",menu2Name);
			mapParam.put("userId",userId);
			mapParam.put("pageType","pageType");

			Result resultObj;
			if(pageType.equals("datagrid")){
				resultObj = menuService.template2menu(mapParam);
			}else if(pageType.equals("datagrid-sourcecode")){
				resultObj = menuService.template2menuSourceCode(mapParam);
			} else {
				resultObj = menuService.template2menu4Chart(mapParam);
			}

			//生成源码
			if(pageType.equals("datagrid-sourcecode")){
				//List<A3jeeCodingDto> a3jeeCodingDtoList = a3jeeCodingService.selectAll().getResultList();
				List<String> _keyRandomList = new ArrayList<String>();
				_keyRandomList.add(keyRandom);
				FreemarkerGen freemarkerGen = new FreemarkerGen();
				//freemarkerGen.execute(_keyRandomList,a3jeeCodingDtoList);
				freemarkerGen.execute(_keyRandomList,3);
			}

	    	this.result = JsonMap.map2Json(resultObj.getResultMap());
			JsonPaginationUtils.responseWriter(response, this.result);
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
		
	}



	/**
	 * 生成single chart 图表二级菜单
	 * @return
	 */
	public String template2menu4chart(){
		HttpServletResponse response = ServletActionContext.getResponse();
		long userId = Long.parseLong(WebUtils.getUserId());
		try {
			long _templateColumnId = Long.parseLong(_id);
			Map<String,Object> mapParam = new HashMap<String, Object>();
			mapParam.put("_templateColumnId",_templateColumnId);
			mapParam.put("menuIdParent",Long.parseLong(menu1Id));
			mapParam.put("menuName",menu2Name);
			mapParam.put("columnName",columnName);
			mapParam.put("userId",userId);
			mapParam.put("pageType","pageType");

			//resultObj = menuService.template2menu4ChartSingle(_templateColumnId, Long.parseLong(menu1Id),pageType,menu2Name,columnName);
			Result resultObj = menuService.template2menu4ChartSingle(mapParam);
	    	this.result = resultObj.getContent();
	    	this.result = JsonMap.map2Json(resultObj.getResultMap());
			JsonPaginationUtils.responseWriter(response, this.result);
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
		
	}


	/**
	 * 启动工作任务
	 * _id： a2Job_id
	 * @return
	 */
	public String timerStartup(){
		try {
			Result resultObj = quartzService.timerStartup(Long.parseLong(_id));

	    	this.result = resultObj.getContent();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
		
	}

	/**
	 * 关闭工作任务
	 * @return
	 */
	public String timerShutdown(){
		try {
			Result resultObj = quartzService.timerShutdown(Long.parseLong(_id));

	    	this.result = resultObj.getContent();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
		
	}

	/**
	 * 重启工作任务
	 * @return
	 */
	public String timerRestart(){
		try {
			Result resultObj = quartzService.timerRestart(Long.parseLong(_id));

	    	this.result = resultObj.getContent();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
		
	}
	
	
	/**
	 * 通过OptionId 查找 option hidden column
	 * 动态隐藏一些无关操作的列；如：选择‘表名直接拼接SQL模板’时，隐藏一些无关的操作属性
	 * 以‘_access’结尾的方法名，在权限系统中不做验证，直接旅行
	 * @return
	 */
	public String queryOptionHidColByOptionId_access(){
		Result resultObj = new Result();
		try {
			List<A1TemplateColumnOptionHidColDto> a1TemplateColumnOptionHidColDtoList 
				= templateService.queryOptionHidColByOptionId(Long.parseLong(optionId));
			
			this.jsonArrayResult = new ArrayList<Map<String,Object>>();
			for(A1TemplateColumnOptionHidColDto optionHidColDto:a1TemplateColumnOptionHidColDtoList){
				String optionHidColId = String.valueOf(optionHidColDto.getId());
				String optionHidColName = optionHidColDto.getColumName();
				Map<String, Object> joCompany = new HashMap<String, Object>();
				joCompany.put("id", optionHidColId);
				joCompany.put("text", optionHidColName);
				this.jsonArrayResult.add(joCompany);
			}
			
			String json = this.jsonArrayResult.toString();

	    	this.result = json;
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonArray";
	}

	/**
	 * check url 是否是有权访问的，控制页面显示用
	 * @return
	 */
	public String authorizeUsingUrlCheck_access(){
		try {
			HttpServletRequest request = WebUtils.getRequest();
			UrlAuthUtils urlAuthUtils = new UrlAuthUtils(request);
			boolean auth = urlAuthUtils.authorizeUsingUrlCheck(url);
			org.json.JSONObject jsonObject = new org.json.JSONObject();
			jsonObject.put("result", auth);

			this.result = jsonObject.toString();
		}catch (Exception e) {
			e.printStackTrace();
			this.result = "error:操作失败："+e.getLocalizedMessage();
		}
		return "jsonResult";
	}

	
	public String getKeyRandom() {
		return keyRandom;
	}
	public void setKeyRandom(String keyRandom) {
		this.keyRandom = keyRandom;
	}
	public Logger getLog() {
		return log;
	}
	public void setLog(Logger log) {
		this.log = log;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	public String getRecordDateStart() {
		return recordDateStart;
	}
	public void setRecordDateStart(String recordDateStart) {
		this.recordDateStart = recordDateStart;
	}
	public String getRecordDateEnd() {
		return recordDateEnd;
	}
	public void setRecordDateEnd(String recordDateEnd) {
		this.recordDateEnd = recordDateEnd;
	}
	public String getSortColumn() {
		return sortColumn;
	}
	public void setSortColumn(String sortColumn) {
		this.sortColumn = sortColumn;
	}
	public String getSortOrder() {
		return sortOrder;
	}
	public void setSortOrder(String sortOrder) {
		this.sortOrder = sortOrder;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public A1OperationlogDto getOprDtoBack() {
		return oprDtoBack;
	}
	public void setOprDtoBack(A1OperationlogDto oprDtoBack) {
		this.oprDtoBack = oprDtoBack;
	}
	public ITemplateService getTemplateService() {
		return templateService;
	}
	public void setTemplateService(ITemplateService templateService) {
		this.templateService = templateService;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public String getTableNameShow() {
		return tableNameShow;
	}
	public void setTableNameShow(String tableNameShow) {
		this.tableNameShow = tableNameShow;
	}
	public String getPrimaryKey() {
		return primaryKey;
	}
	public void setPrimaryKey(String primaryKey) {
		this.primaryKey = primaryKey;
	}
	public long getA1TemplateTableId() {
		return a1TemplateTableId;
	}
	public void setA1TemplateTableId(long a1TemplateTableId) {
		this.a1TemplateTableId = a1TemplateTableId;
	}
	public String getColumnName() {
		return columnName;
	}
	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}
	public String getColumnShowName() {
		return columnShowName;
	}
	public void setColumnShowName(String columnShowName) {
		this.columnShowName = columnShowName;
	}
	public String getColumnNameSql() {
		return columnNameSql;
	}
	public void setColumnNameSql(String columnNameSql) {
		this.columnNameSql = columnNameSql;
	}
	public String getColumnNameSqlSum() {
		return columnNameSqlSum;
	}
	public void setColumnNameSqlSum(String columnNameSqlSum) {
		this.columnNameSqlSum = columnNameSqlSum;
	}
	public int getNeedSum() {
		return needSum;
	}
	public void setNeedSum(int needSum) {
		this.needSum = needSum;
	}
	public int getIsFrozenColumn() {
		return isFrozenColumn;
	}
	public void setIsFrozenColumn(int isFrozenColumn) {
		this.isFrozenColumn = isFrozenColumn;
	}
	public int getSort() {
		return sort;
	}
	public void setSort(int sort) {
		this.sort = sort;
	}
	public int getIsHidden() {
		return isHidden;
	}
	public void setIsHidden(int isHidden) {
		this.isHidden = isHidden;
	}
	public long getA1TemplateConditionId() {
		return a1TemplateConditionId;
	}
	public void setA1TemplateConditionId(long a1TemplateConditionId) {
		this.a1TemplateConditionId = a1TemplateConditionId;
	}
	public int getIsMultiQuery() {
		return isMultiQuery;
	}
	public void setIsMultiQuery(int isMultiQuery) {
		this.isMultiQuery = isMultiQuery;
	}
	public String getItemName() {
		return itemName;
	}
	public void setItemName(String itemName) {
		this.itemName = itemName;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getKeyName() {
		return keyName;
	}
	public void setKeyName(String keyName) {
		this.keyName = keyName;
	}
	public String getValueName() {
		return valueName;
	}
	public void setValueName(String valueName) {
		this.valueName = valueName;
	}


	public String get_id() {
		return _id;
	}


	public void set_id(String _id) {
		this._id = _id;
	}


	public List<Map<String, Object>> getJsonArrayResult() {
		return jsonArrayResult;
	}


	public void setJsonArrayResult(List<Map<String, Object>> jsonArrayResult) {
		this.jsonArrayResult = jsonArrayResult;
	}


	public ISecurityV2Service getSecurityV2Service() {
		return securityV2Service;
	}


	public void setSecurityV2Service(ISecurityV2Service securityV2Service) {
		this.securityV2Service = securityV2Service;
	}


	public String getMenu1Id() {
		return menu1Id;
	}


	public void setMenu1Id(String menu1Id) {
		this.menu1Id = menu1Id;
	}


	public String getOptionId() {
		return optionId;
	}


	public void setOptionId(String optionId) {
		this.optionId = optionId;
	}


	public IQuartzService getQuartzService() {
		return quartzService;
	}


	public void setQuartzService(IQuartzService quartzService) {
		this.quartzService = quartzService;
	}


	public String getPageType() {
		return pageType;
	}


	public void setPageType(String pageType) {
		this.pageType = pageType;
	}


	public String getMenu2Name() {
		return menu2Name;
	}


	public void setMenu2Name(String menu2Name) {
		this.menu2Name = menu2Name;
	}

	public String get_keyRandom() {
		return _keyRandom;
	}

	public void set_keyRandom(String _keyRandom) {
		this._keyRandom = _keyRandom;
	}

	public String getMenu2Id() {
		return menu2Id;
	}

	public void setMenu2Id(String menu2Id) {
		this.menu2Id = menu2Id;
	}
}
